<include file="public/header" />
<body>
<div class="layui-fluid">
  <div class="layui-row">
    <form class="layui-form" action="{:url('Merchant/edit')}">
      <div class="layui-form-item">
<!--        <label for="username" class="layui-form-label">-->
<!--          <span class="x-red">*</span>名称-->
<!--        </label>-->
<!--        <div class="layui-input-inline">-->
<!--          <input type="text" id="name" name="name" value="{$info.name}" required="" lay-verify="required"-->
<!--                 autocomplete="off" class="layui-input">-->
<!--        </div>-->
<!--        <if condition="$info.id eq '' " >-->
<!--        <div class="layui-form-item">-->
<!--          <label class="layui-form-label">密码<span style="color: red;">(密码)</span></label>-->
<!--          <div class="layui-input-block">-->
<!--            <input type="password" name="password"  style="width: 500px"  y lay-verify="required"  value="" autocomplete="off" placeholder="" class="layui-input">-->
<!--          </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item">-->
<!--          <label class="layui-form-label">密码<span style="color: red;">(确认密码)</span></label>-->
<!--          <div class="layui-input-block">-->
<!--            <input type="password" name="password_confirm"  style="width: 500px"  lay-verify="required"  value="" autocomplete="off" placeholder="" class="layui-input">-->
<!--          </div>-->
<!--        </div>-->
<!--        </if>-->
        <div class="layui-form-item">
          <label class="layui-form-label">appid<span style="color: red;">(必填)</span></label>
          <div class="layui-input-block">
            <input type="number" name="appid" id="appid" style="width: 200px" readonly lay-verify="required"  value="{$info.appid}" autocomplete="off" placeholder="" class="layui-input">
          </div>
          <div class="layui-inline">
            <a href="javascript:;" class="layui-btn layui-btn-warm" id="changeValueBtn">点击生产Appid和公钥</a>
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">secret<span style="color: red;">(必填)</span></label>
          <div class="layui-input-block">
            <input type="text" name="secret" id="secret"  style="width: 500px"  readonly lay-verify="required"  value="{$info.secret}" autocomplete="off" placeholder="" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">key<span style="color: red;">(必填)</span></label>
          <div class="layui-input-block">
            <input type="text" name="key" id="key"  style="width: 300px"  readonly lay-verify="required"  value="{$info.key}" autocomplete="off" placeholder="" class="layui-input">
          </div>
          <div class="layui-inline">
            <a href="javascript:;" class="layui-btn layui-btn-warm" id="changeKey">点击生产私钥</a>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">启用ip验证</label>
          <div class="layui-input-block">
            <input type="radio" name="ip_switch" value="1" title="是" <if condition="$info.ip_switch eq 1 or $info.ip_switch eq ''">checked=""</if> >
            <input type="radio" name="ip_switch" value="0" title="否" <if condition="$info.ip_switch eq '0' ">checked=""</if> >
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">ip<span style="color: red;">(多个,隔开必填)</span></label>
          <div class="layui-input-block">
            <input type="text" name="ip" style="width: 500px"   value="{$info.ip}" autocomplete="off" placeholder="" class="layui-input">
          </div>
        </div>
<!--        <div class="layui-form-item">-->
<!--          <label class="layui-form-label">启用</label>-->
<!--          <div class="layui-input-block">-->
<!--            <input type="radio" name="status" value="1" title="是" <if condition="$info.status eq 1 or $info.status eq ''">checked=""</if> >-->
<!--            <input type="radio" name="status" value="0" title="否" <if condition="$info.status eq '0' ">checked=""</if> >-->
<!--          </div>-->
<!--        </div>-->

        <div class="layui-form-item" >
          <div class="layui-input-block">
            <input type="hidden" name="id" value="{$info.id}">
            <button type="button"  class="layui-btn" lay-submit=""  lay-filter="addEdit">保存</button>
          </div>
        </div>
    </form>
  </div>
</div>
<script>

  layui.use(['form', 'layedit', 'laydate','jquery','upload'], function(){
    var form = layui.form
            ,layer = layui.layer
            , $ = layui.jquery
            , upload = layui.upload
            ,laydate = layui.laydate
            ,inputTags = layui.inputTags
    var layedit = layui.layedit;
    //拖拽上传

    function generateRandomString(length, type) {
      let characters; // 将变量声明移到函数顶部

      if (type === 'str') {
        characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      } else {
        characters = '0123456789';
      }

      let result = '';
      for (let i = 0; i < length; i++) {
        const randomIndex = Math.floor(Math.random() * characters.length);
        result += characters[randomIndex];
      }

      return result;
    }
    // 使用 jQuery 监听按钮点击事件
    $('#changeValueBtn').on('click', function(){

      const appId = generateRandomString(10,'number');
      const Secret = generateRandomString(32,'str'); // Adjust length as needed
      $('#appid').val(appId);
      $('#secret').val(Secret);
    });

    // 使用 jQuery 监听按钮点击事件
    $('#changeKey').on('click', function(){

      const key = generateRandomString(16,'str'); // Adjust length as needed
      $('#key').val(key);

    });


    form.on('submit(addEdit)', function(data){
      $.post($('form').attr('action'),data.field,function(data){
        if(data.code == 200){
          layer.msg(data.msg);
          setTimeout(function () {
            window.history.back();
          },2000)
          xadmin.close();
          xadmin.father_reload();
        }else {
          layer.msg(data.msg);
        }
      });
      return false;
    });
  });

</script>
</body>

</html>
